# class Solution(object):
#     def rotate(self, nums, k):
#         """
#         :type nums: List[int]
#         :type k: int
#         :rtype: None Do not return anything, modify nums in-place instead.
#         """
#         while k > 0:
#             tmp = nums[-1]
#             end = len(nums) - 2
#             while end >= 0 :
#                 nums[end + 1] = nums[end]
#                 end = end - 1
#             nums[0] = tmp
#             k = k - 1

#一个逆置hanshu
def reverse(nums, left, right):
    while left < right:
        tmp = nums[right]
        nums[right] = nums[left]
        nums[left] = tmp
        left  = left + 1
        right = right - 1

def rotate(nums, k):
    #1.逆置右边kge
    reverse(nums, len(nums) - k, len(nums) - 1)
    reverse(nums, 0, len(nums) - k - 1)
    reverse(nums, 0, len(nums) - 1)

nums = [1,2,3,4,5,6,7,8]
rotate(nums, 3)
print(nums)